/*
 * Copyright (c) 2010 CCX(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCX(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCX(China) Co.,Ltd.
 *
 * Author: zhaosj
 * Date: 2010-10-29 下午12:18:53
 */
package com.jxl;

import java.io.FileInputStream;
import java.io.InputStream;

import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;

/**
 * @author zhaosj
 * 
 */
public class Test {

	public String readxls(String path) {
		StringBuffer sb = new StringBuffer("");
		try {
			InputStream is = new FileInputStream(path);
			
			//打开工作薄
			Workbook book = Workbook.getWorkbook(is);
			
			//打开工作表
			Sheet sheet = book.getSheet(0);
			
			// 得到所有的行数
			Integer rows = sheet.getRows();
			
			// 得到所有的列数
			Integer cols = sheet.getColumns();
			
			Cell cell;

			for (int r = 0; r < rows; r++) {
				for (int c = 0; c < cols; c++) {
					
					//获取单元格
					cell = sheet.getCell(c, r);
					String content = "";

					if (cell.getType() != CellType.EMPTY) {
						
						//读取内容
						content = cell.getContents()+",";
						
						System.out.println("col:" + c + " row:" + r + " type:" + cell.getType());
					}
					
					sb.append(content);
					/**
					 * 换行显示 new Xls().insert(xls, cell.getContents()+"\r\n", append);
					 */
				}
			}

			book.close();

		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("解析错误");
		}
		return sb.toString();

	}

	public static void main(String[] args) {
		String path = "F:\\MYDOCUMENT\\计划样板.xls";

		Test t = new Test();
		System.out.println(t.readxls(path));
	}

}
